package com.example.demo.controller;

import com.example.demo.entity.Classes;
import com.example.demo.entity.Subscribe;
import com.example.demo.entity.User;
import com.example.demo.mapper.ClassesMapper;
import com.example.demo.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/classes")
public class ClassesController {
    @Autowired
    private ClassesMapper classesMapper;
    @Autowired
    private ClassesService classesService;
    @GetMapping
    public List<Classes> index() {return classesMapper.findAll();}

    @GetMapping("/page")
    public Map<String,Object> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        pageNum = (pageNum-1)*pageSize;
        List<Classes> data = classesService.selectPage(pageNum,pageSize);
        Integer total = classesMapper.selectTotal();
        Map<String,Object> res = new HashMap<>();
        res.put("data",data);
        res.put("total",total);
        return res;
    }
    @PostMapping
    public Integer save(@RequestBody Classes classes) { return classesMapper.insert(classes); }
    //查询不同类型的所有数据
    @GetMapping("/type")
    public List<Classes> labTypeSelect(@RequestParam Integer labType){
        return classesService.labTypeSelect(labType);
    }
    //?查询不同类型的所有数据,分页显示You are using the Lightweight API Client, sign in or create an account to work with collections, environments and
    @GetMapping("/tPage")
    public List<Classes> labTypeSelectPage(@RequestParam Integer labType,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        pageNum = (pageNum-1)*pageSize;
        return classesService.labTypeSelectPage(labType,pageNum,pageSize);
    }

    ////根据id获取实验室详情
    @GetMapping("/detail")
    public Classes getDetail(@RequestParam Integer id){
        return classesService.getDetail(id);
    }
}

